//
//  PopoverViewController.swift
//  HJWeibo
//
//  Created by huangjiong on 16/2/1.
//  Copyright © 2016年 huangjiong. All rights reserved.
//

import UIKit

class PopoverViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        datas = ["1","2","3","4","5"]
        
        //添加背景
        view.addSubview(bgImageView)
        //消除添加背景图片后的白边
        view.backgroundColor = UIColor.clearColor()
        
        view.addSubview(tableView)
       
    }

   //背景view
    lazy var bgImageView: UIImageView = {
        
        let imgView = UIImageView(image: UIImage(named: "popover_background"))
        
        imgView.frame = self.view.bounds
        print("加载了")
        return imgView
    }()
    
    //tableView
    lazy var tableView:UITableView = {
        
        let kSpace: CGFloat = 15
        
        let tb = UITableView(frame: CGRect(x: kSpace, y: kSpace, width: self.view.bounds.size.width - kSpace * 2, height: self.view.bounds.size.height - kSpace * 2), style: UITableViewStyle.Plain)
        tb.delegate = self
        tb.dataSource = self
        return tb
    }()
    
    //数据源
    lazy var datas:NSMutableArray = {
        
        var mArr = NSMutableArray()
        
        return mArr
    }()
    
}

extension PopoverViewController:UITableViewDataSource,UITableViewDelegate
{
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return datas.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCellWithIdentifier("cell")
        
        if cell == nil
        {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
        }
        
        cell?.textLabel!.text = datas[indexPath.row] as? String
        
        return cell!
    }
    
}
